import request from '@/utils/request';
import type { RoleResponseData, Records, MenuResponseData } from './type';
enum API {
    // 获取角色分页列表
    GET_ROLE_LIST = '/admin/acl/role',
    // 新增职位
    ADD_ROLE = '/admin/acl/role/save',
    // 更新职位
    UPDATE_ROLE = '/admin/acl/role/update',
    // 删除职位
    DELETE_ROLE = '/admin/acl/role/remove',
    // 获取职位详情
    GET_ROLE_DETAIL = '/admin/acl/permission/toAssign',
    // 给职位分配权限
    ASSIGN_PERMISSION = '/admin/acl/permission/doAssign',
}
// 获取角色分页列表
export const reqGetRoleList = (page: number, limit: number, roleName: string) =>
    request.get<any, RoleResponseData>(
        API.GET_ROLE_LIST + `/${page}/${limit}/?roleName=${roleName}`,
    );
// 新增或更新职位
export const reqAddOrUpdateRole = (data: Records) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATE_ROLE, data);
    } else {
        return request.post<any, any>(API.ADD_ROLE, data);
    }
};
// 删除职位
export const reqDeleteRole = (id: number) =>
    request.delete<any, any>(API.DELETE_ROLE + `/${id}`);

// 获取职位详情
export const reqGetRoleDetail = (roleId: number) =>
    request.get<any, MenuResponseData>(API.GET_ROLE_DETAIL + `/${roleId}`);

// 给职位分配权限
export const reqAssignPermission = (roleId: number, permissionId: number[]) =>
    request.post<any, any>(
        API.ASSIGN_PERMISSION +
            `/?roleId=${roleId}&permissionId=${permissionId}`,
    );
